package org.teremail.message;

import java.util.Collections;
import java.util.Iterator;
import java.util.List;

public class MultipartMessage implements Multipart, Message {

    private final ContentHeaders contentHeader;
    private final String preamble;
    private final String epilogue;
    private final MessageHeaders messageHeader;
    private final List<Entity> parts;
    private final String id;

    public MultipartMessage(String id, ContentHeaders contentHeader, 
            MessageHeaders header, String preamble, List<Entity> parts, 
            String epilogue) {
        this.id = id;
        this.contentHeader = contentHeader;
        this.messageHeader = header;
        this.preamble = preamble;
        this.epilogue = epilogue;
        this.parts = Collections.unmodifiableList(parts);
    }
    
    public MultipartMessage(ContentHeaders contentHeader, MessageHeaders header, 
            String preamble, List<Entity> parts, String epilogue) {
        this(Entity.UNSAVED_ID, contentHeader, header, preamble, parts, epilogue);
    }
    
    public String getId() {
        return id;
    }
    
    public ContentHeaders getContentHeader() {
        return contentHeader;
    }

    public String getEpilogue() {
        return epilogue;
    }

    public String getPreamble() {
        return preamble;
    }

    public MessageHeaders getHeader() {
        return messageHeader;
    }
    
    public Iterator<Entity> iterator() {
        return parts.iterator();
    }

    public void accept(EntityVisitor v) {
        v.visitMultipartMessage(this);
    }

    public EntityType getType() {
        return EntityType.MULTIPART_MESSAGE;
    }

    public boolean isMultipart() {
        return true;
    }
}
